import { defineStore } from 'pinia'
import axios from 'axios'

const API_BASE_URL = 'http://localhost:3001/api'

export const useDashboardStore = defineStore('dashboard', {
  state: () => ({
    systemReport: null,
    loading: false,
    error: null
  }),

  actions: {
    async fetchSystemReport() {
      this.loading = true
      this.error = null
      try {
        const response = await axios.get(`${API_BASE_URL}/dashboard/report`)
        const data = response.data.data || response.data
        this.systemReport = data
        return this.systemReport
      } catch (err) {
        this.error = err.response?.data?.error || '获取系统报告失败'
        console.error('获取系统报告失败:', err)
        throw err
      } finally {
        this.loading = false
      }
    }
  }
})
